package com.itheima.jobs;

import com.itheima.Utils.QiniuUtil;
import com.itheima.Utils.redisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;

    public void clearImg(){
        Set<String> sdiff = jedisPool.getResource().sdiff(redisUtil.RedisConstant.FOLDE_RREDIS, redisUtil.RedisConstant.FOLDE_MYSQL);

        if(sdiff!=null){
            for (String s : sdiff) {
                //去七牛云里面删除图片
                String[] split = s.split("/");
                QiniuUtil.deleteFileFromQiniu(split[split.length-2]+"/"+split[split.length-1]);
                //去redis中删除垃圾图片
                jedisPool.getResource().srem(redisUtil.RedisConstant.FOLDE_RREDIS,s);
            }
        }
    }
}
